<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2019/6/20
  Time: 18:54
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <link rel="stylesheet" href="/sharing/layuiadmin/layui/css/layui.css"></link>
    <link rel="stylesheet" href="/sharing/layuiadmin/layui/css/layui.css"  media="all">
    <script type="text/javascript" src="/sharing/js/jquery.min.3.1.0.js"></script>
</head>

<body>
<form  class="layui-form" id="myForm" name="myForm" action="#" method="post" enctype="application/x-www-form-urlencoded">

    <div class="layui-form-item">
        <label class="layui-form-label">管理员编号</label>
        <div class="layui-input-inline">
            <input id="userId" name="userId" lay-verify="userId" type="text" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">管理员姓名</label>
        <div class="layui-input-inline">
            <input id="userName" name="userName" lay-verify="userName" type="text" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">管理员密码</label>
        <div class="layui-input-inline">
            <input id="passWord" name="passWord" type="password" lay-verify="passWord" value="123456" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">管理员电话</label>
        <div class="layui-input-inline">
            <input id="telephone" name="telephone"  lay-verify="telephone" type="text" value=""  class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input id="remarks" name="remarks"  type="text" value=""  class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="buttons">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script src="/sharing/layuiadmin/layui/layui.js"></script>
<script >
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            //验证姓名
            userId: function(value){
                if(value<11110){
                    return '用户编号不能小于11110';
                }
            }
            ,userName:function (value) {
                if (value.length<=0) {
                    return '用户名不能为空';
                }
            }
            ,passWord:function (value) {
                var p=/^[\S]{6,12}$/;
                if (!p.test(value)) {
                    return '密码必须6到12位，且不能出现空格';
                }
            }
            ,telephone:function (value) {
                var p=/^1[3456789]\d{9}$/;
                var s = /^[0][1-9]{2,3}-[0-9]{5,10}$/;
                if(!p.test(value)&&!s.test(value)){
                    return '号码不正确';
                }
            }
        });

        //监听提交
        form.on('submit(buttons)', function(data){
            $.ajax({
                url: "http://localhost:8080/grails_day2/login/saveUser",
                dataType: "json",
                type: 'post',
                data: $("#myForm").serialize(),
                success: function (data) {
                    if (data.msg == 1) {
                        layer.open({
                            content: '新增成功'
                            , btn: ['确定']
                            , yes: function (index, layero) {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            }
                        });
                    } else {
                        layer.open({
                            content: '新增失败'
                            , btn: ['确定']
                            , yes: function (index, layero) {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            }
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</html>